import {useRef} from 'react';
import {useFrame} from '@react-three/fiber';


const Lights = (props) => {

  const lightRef = useRef();

  useFrame((state, delta) => {
    if(lightRef.current){
      lightRef.current.position.z = state.camera.position.z + 1 - 4;
      lightRef.current.target.position.z = state.camera.position.z - 4;
      lightRef.current.target.updateMatrixWorld();
    }
  })

  return <>
    <ambientLight intensity={0.5}/>
    <directionalLight
      ref={lightRef}
      color="#fff"
      position={[0, 4, 4]}
      intensity={1.5}
      castShadow
      shadow-mapSize={[1024, 1024]}
      shadow-camera-near={0.1}
      shadow-camera-far={1000}
      shadow-camera-left={-40}
      shadow-camera-right={40}
      shadow-camera-top={40}
      shadow-camera-bottom={-40}
    />
  </>

}

export default Lights;
